/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.core.validate.QueryGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdMetalMaterialBo;
import com.comac.ins.isfd.domain.bo.query.IsfdMetalMaterialQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdMetalMaterialVo;
import com.comac.ins.isfd.service.IIsfdMetalMaterialService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 【材料库金属材料】
 *
 * @author Lion Li
 * @date 2024-08-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/metalMaterial")
public class IsfdMetalMaterialController extends BaseController {

    private final IIsfdMetalMaterialService isfdMetalMaterialService;

    /**
     * 查询【材料库金属材料】列表
     */
    @SaCheckPermission("isfd:metalMaterial:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdMetalMaterialVo> list(@RequestBody IsfdMetalMaterialQueryBo bo) {
        return isfdMetalMaterialService.queryPageList(bo);
    }

    /**
     * 导出【材料库金属材料】列表
     */
    @SaCheckPermission("isfd:metalMaterial:export")
    @Log(title = "【材料库金属材料】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdMetalMaterialQueryBo bo, HttpServletResponse response) {
        List<IsfdMetalMaterialVo> list = isfdMetalMaterialService.queryList(bo);
        ExcelUtil.exportExcel(list, "【材料库金属材料】", IsfdMetalMaterialVo.class, response);
    }

    /**
     * 获取【材料库金属材料】详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:metalMaterial:query")
    @GetMapping("/{id}")
    public R<IsfdMetalMaterialVo> getInfo(@NotNull(message = "主键不能为空")
                                          @PathVariable Long id) {
        return R.ok(isfdMetalMaterialService.queryById(id));
    }

    /**
     * 新增【材料库金属材料】
     */
    @SaCheckPermission("isfd:metalMaterial:add")
    @Log(title = "【材料库金属材料】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdMetalMaterialBo bo) {
        return toAjax(isfdMetalMaterialService.insertByBo(bo));
    }

    /**
     * 修改【材料库金属材料】
     */
    @SaCheckPermission("isfd:metalMaterial:edit")
    @Log(title = "【材料库金属材料】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdMetalMaterialBo bo) {
        return toAjax(isfdMetalMaterialService.updateByBo(bo));
    }

    /**
     * 删除【材料库金属材料】
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:metalMaterial:remove")
    @Log(title = "【材料库金属材料】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdMetalMaterialService.deleteWithValidByIds(List.of(ids), true));
    }
}
